//
//  MoneyTypeViewController.m
//  随手记
//
//  Created by Medalands on 15/11/5.
//  Copyright (c) 2015年 Medalands. All rights reserved.
//

#import "MoneyTypeViewController.h"

@interface MoneyTypeViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic , strong) UITableView *tmpTableView;
@property (nonatomic , strong) NSArray *tmpArray;
@property (nonatomic , strong) UILabel *iconLbabel;
@end

@implementation MoneyTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setUpTmpArray];
    [self setUpTmpTableView];
    self.iconLbabel = [[UILabel alloc] initWithFrame:KRECT(KScreenWidth - 40, 10, 30, 24)];
    [self.iconLbabel setText:@"✔️"];
}

- (void) setUpTmpTableView{
    self.tmpTableView = [[UITableView alloc] initWithFrame:KRECT(0, 0, KScreenWidth, KScreenHeight-64) style:(UITableViewStyleGrouped)];
    [self.tmpTableView setDelegate:self];
    [self.tmpTableView setDataSource:self];
    [self.view addSubview:self.tmpTableView];
}

- (void) setUpTmpArray{
    self.tmpArray = @[@"CNY 人民币",@"HKD 港币",@"USD 美元",@"JPY 日元",@"TWD 台币",@"EUR 欧元",@"GBP 英镑",@"AUD 澳币",@"KRW 韩币",@"THB 泰铢"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.tmpArray.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"ID";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:ID];
    }
    [cell.textLabel setText:self.tmpArray[indexPath.row]];
    
    
    if ([self.getString isEqualToString:self.tmpArray[indexPath.row]]) {
        [cell addSubview:self.iconLbabel];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self.iconLbabel removeFromSuperview];
    [cell addSubview:self.iconLbabel];
    if (self.sendToStringType) {
        self.sendToStringType(cell.textLabel.text);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
